<?php
namespace app\admin\controller\system;
use app\common\annotation\NodeAnnotation;
use app\common\controller\Admin;
use app\common\traits\ControllerCurd;
use think\Request;
/**
 * @package app\admin\controller\system
 * @NodeAnnotation(
 *     title="存储服务",
 *     is_menu=0,
 *     is_view=0
 * )
 */
class Storage extends Admin
{
    /**
     * @NodeAnnotation(
     *     title="文件存储",
     *     parent="admin/system.storage",
     *     MenuRoot="admin/system.setting"
     * )
     */
    public function index()
    {
        $storage = get_option('storage');

        if (empty($storage)) {
            $storage['type']     = 'Local';
            $storage['storages'] = ['Local' => ['name' => '本地']];
        } else {
            if (empty($storage['type'])) {
                $storage['type'] = 'Local';
            }
            if (empty($storage['storages']['Local'])) {
                $storage['storages']['Local'] = ['name' => '本地'];
            }
        }
        $this->assign($storage);
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="文件存储设置提交",
     *     parent="admin/system.storage",
     *     MenuRoot="admin/system.setting",
     *     is_menu=0
     * )
     */
    public function settingPost()
    {
        $post = $this->request->post();
        $storage = get_option('storage');
        $storage['type'] = $post['type'];
        set_option('storage', $storage);
        $this->success("设置成功");
    }

}